package com.wallet.service.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wallet.dao.ArticleDao;
import com.wallet.entity.Article;
import com.wallet.entity.example.ArticleExample;
import com.wallet.entity.result.JsonResult;
import com.wallet.entity.result.ResultCode;
import com.wallet.service.BaseService;

@Service
public class ArticleServiceImpl implements BaseService<Article, ArticleExample> {
	
	@Autowired
	private ArticleDao articleDao;

	@Override
	public int save(Article article) {
		return articleDao.insert(article);
	}

	@Override
	public int insertBatch(List<Article> list) {
		return articleDao.insertBatch(list);
	}

	@Override
	public int del(Integer id) {
		return articleDao.deleteByPrimaryKey(id);
	}

	@Override
	public int upd(Article article) {
		return articleDao.updateByPrimaryKey(article);
	}

	@Override
	public Article getDetail(Integer id) {
		return articleDao.selectByPrimaryKey(id);
	}

	@Override
	public JsonResult showPage(Integer page, Integer size) {
		JsonResult result=new JsonResult();
		if(page!=null) {
			PageHelper.startPage(page, size);	
		}
		Map<String, Object>data=new HashMap<String, Object>();
		List<Article> list=articleDao.selectAll();
		PageInfo<Article> articles=new PageInfo<Article>(list);
		Integer total=articleDao.selectCount();
		data.put("items", articles.getList());
		data.put("total", total);
		result.setCode(ResultCode.SUCCESS.getVal());
		result.setData(data);
		return result;
	}

	@Override
	public Integer getCount() {
		return articleDao.selectCount();
	}

	@Override
	public List<Article> selectAll() {
		return articleDao.selectAll();
	}

	@Override
	public List<Article> selectByExample(ArticleExample example) {
		// TODO Auto-generated method stub
		return null;
	}

}
